package com.myapp.ruyixing.utils;

import android.content.Context;
import android.view.View;
import android.widget.Toast;

public class UIUtils {

	public static final void setViewVisibility(View v, boolean visible) {
		v.setVisibility(visible ? View.VISIBLE : View.GONE);
	}
	
	public static final void showToast(Context context, String message) {
		Toast.makeText(context, message, Toast.LENGTH_LONG).show();
	}
	
	public static final String[] findPhoneNumbers(String phoneNumber) {
		int areaCodeIndex = phoneNumber.indexOf("-");
		String areaCode = null;
		if (areaCodeIndex >= 0) {
			areaCode = phoneNumber.substring(0, areaCodeIndex);
		}
		String[] phoneNumbers = phoneNumber.split("[(\\)(/)\\s]+");
		for (int i = 0; i < phoneNumbers.length; i++) {
			String pn = phoneNumbers[i];
			if (pn.length() < 11 && areaCode != null
					&& !pn.startsWith(areaCode)) {
				phoneNumbers[i] = areaCode + "-" + pn;
			}
		}
		
		return phoneNumbers;
	}
}
